<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
  <meta name="baidu-site-verification" content="code-kg5UjKJZM2" />
   
  <meta name="keywords" content="活,炼" />
   
  <meta name="description" content="shimmerjordan" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    CCF 201809-4 再卖菜 |  丛烨-shimmerjordan
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
  
<link rel="stylesheet" href="/css/custom.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'G-Q0DT8B8VJW', 'auto');
ga('send', 'pageview');

</script>



  
<script>
var _hmt = _hmt || [];
(function() {
	var hm = document.createElement("script");
	hm.src = "https://hm.baidu.com/hm.js?6d06f826e125297d4ce0fa7a1449328e";
	var s = document.getElementsByTagName("script")[0]; 
	s.parentNode.insertBefore(hm, s);
})();
</script>


<link rel="alternate" href="/atom.xml" title="丛烨-shimmerjordan" type="application/atom+xml">
</head>

</html>

	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
	<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-CCF-201809-4-再卖菜"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  CCF 201809-4 再卖菜
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/02/16/CCF20180904/" class="article-date">
  <time datetime="2020-02-16T05:40:55.000Z" itemprop="datePublished">2020-02-16</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">11 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>出自CCF 201809-4 再卖菜，本文提供了两种思路解决此问题。主要涉及差分约束的解决策略以及搜索 + 剪枝操作方案。</p>
<span id="more"></span>
<h1 id="题面"><a href="#题面" class="headerlink" title="题面"></a>题面</h1><p>时间限制：    1.0s<br>内存限制：    256.0MB<br>问题描述：    </p>
<p>　　在一条街上有n个卖菜的商店，按1至n的顺序排成一排，这些商店都卖一种蔬菜。<br>　　第一天，每个商店都自己定了一个正整数的价格。店主们希望自己的菜价和其他商店的一致，第二天，每一家商店都会根据他自己和相邻商店的价格调整自己的价格。具体的，每家商店都会将第二天的菜价设置为自己和相邻商店第一天菜价的平均值（用去尾法取整）。<br>　　注意，编号为1的商店只有一个相邻的商店2，编号为n的商店只有一个相邻的商店n-1，其他编号为i的商店有两个相邻的商店i-1和i+1。<br>　　给定第二天各个商店的菜价，可能存在不同的符合要求的第一天的菜价，请找到符合要求的第一天菜价中字典序最小的一种。<br>　　字典序大小的定义：对于两个不同的价格序列(a1, a2, …, an)和(b1, b2, b3, …, bn)，若存在i(i&gt;=1), 使得ai&lt;bi，且对于所有j&lt;i，aj=bj，则认为第一个序列的字典序小于第二个序列。</p>
<p>输入格式</p>
<p>　　输入的第一行包含一个整数n，表示商店的数量。<br>　　第二行包含n个正整数，依次表示每个商店第二天的菜价。  </p>
<p>输出格式</p>
<p>　　输出一行，包含n个正整数，依次表示每个商店第一天的菜价。</p>
<p>样例输入</p>
<p>　　8<br>　　2 2 1 3 4 9 10 13  </p>
<p>样例输出</p>
<p>　　2 2 2 1 6 5 16 10  </p>
<p>数据规模和约定</p>
<p>　　对于30%的评测用例，2&lt;=n&lt;=5，第二天每个商店的菜价为不超过10的正整数；<br>　　对于60%的评测用例，2&lt;=n&lt;=20，第二天每个商店的菜价为不超过100的正整数；<br>　　对于所有评测用例，2&lt;=n&lt;=300，第二天每个商店的菜价为不超过100的正整数。<br>　　请注意，以上都是给的第二天菜价的范围，第一天菜价可能会超过此范围。  </p>
<h1 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h1><p>这道题是非常经典的最短路解差分约束问题。首先，这道题要求字典序最小，我们考虑将所有的不等式都变成 \(x_i-x_j \geq k\)，反过来求最长路即可。</p>
<p>首先分析为什么差分约束可以用最短路求解：<br>因为只有二元一次的不等式建立的差分约束才能用最短路求解，因为图中的两个点是一一对应建立关系的。<br>举个例子，对于 \(x_j-x_i \leq k\)，这样的不等式非常像最短路的松弛操作。假设我们有两个点, \(i\)和\(j\)，在最短路中会有转移方程 <code>if(dist[j]-dist[i] &gt; k)  dist[j]=dist[i]+k</code> 。我们可以发现，当前\(i\)到\(j\)有一条边权值为k，这是相当于对\(j\)更新。原来的dist[j]不满足约束条件，也就是 dist[j]-dist[i]&gt;k，更新后一定满足约束条件，更新后的dist[j]就满足dist[j]-dist[i]&lt;=k，而dist[i]就相当于 \(x_i\)，也就是 \(x_j-x_i \leq k\)。而且这个更新后得到的序列是字典序最大的。为什么？很简单，因为当dist[j]-dist[i]&gt;k时让dist[j]-dist[i]&lt;=k，dist[j]可以更新到dist[i]+k-n，n可以取任意正整数都可以满足条件，但这里的更新就相当于n取零，使得dist[j]有最大值。</p>
<p>然而这道题要求字典序最小，我们只需要把所有不等式都变成 \(x_i-x_j \geq k\)，反过来求最长路即可，其原理同最短路。</p>
<p>设第二天的第 \(i\) 家店的价格是 \(a_i\)，那么第一天第 \(i\) 家店的价格为 \(x_i\)。我们已知 \(a_i\) 的序列，要求 \(x_i\) 的最小字典序。<br>首先，我们可以得到的关系有:  </p>
<script type="math/tex; mode=display">\begin{cases}
a_1=(x_1+x_2)/2 \\\  
a_2=(x_1+x_2+x_3)/3 \\\  
a_3=(x_2+x_3+x_4)/3 \\\  
\cdots \cdots \\\  
a_{n-1}=(x_{n-2}+x_{n-1}+x_n)/3 \\\ 
a_n=(x_{n-1}+x_n)/2 \\\
\end{cases}</script><p>由于题意为去尾法取整，因此可以将上述关系进一步转化为：</p>
<script type="math/tex; mode=display">\begin{cases}
a_1=(x_1+x_2)/2-0.5 \quad or \quad (x_1+x_2)/2 \\\  
a_2 =(x_1+x_2+x_3)/3-1/3 \quad or \quad (x_1+x_2+x_3)/3-2/3 \\\  
\quad or \quad (x_1+x_2+x_3)/3  \\\  
a_3 =(x_2+x_3+x_4)/3-1/3 \quad or \quad (x_2+x_3+x_4)/3-2/3 \\\  
\quad or \quad (x_2+x_3+x_4)/3  \\\  
\cdots \cdots \\\  
a_{n-1}=(x_{n-2}+x_{n-1}+x_n)/3-1/3 \quad or \quad (x_{n-2}+x_{n-1}+x_n)/3-2/3 \\\  
\quad or \quad (x_{n-2}+x_{n-1}+x_n)/3 \\\  
a_n=(x_{n-1}+x_n)/2-0.5 \quad or \quad (x_{n-1}+x_n)/2
\end{cases}</script><p>进一步的，我们将此关系改写为不等式约束：</p>
<script type="math/tex; mode=display">\begin{cases}
2 \cdot a_1 \leq x_1+x_2 \leq 2 \cdot a_1+1 \\\  
3 \cdot a_2 \leq x_1+x_2+x_3 \leq 3 \cdot a_2+2 \\\  
3 \cdot a_3 \leq x_2+x_3+x_4 \leq 3 \cdot a_3+2 \\\  
\cdots \cdots \\\  
3 \cdot a_{n-1} \leq x_{n-2}+x_{n-1}+x_n \leq 3 \cdot a_n+2 \\\  
2 \cdot a_n \leq x_{n-1}+x_n \leq 2 \cdot a_n+1  
\end{cases}</script><p>接下来分析建图问题：</p>
<p>首先这里涉及到多项式之和，但是差分约束系统是二元一次不等式，所以我们需要对其进行重构造。这里设 \(s_i\) 为0到 \(i\)的 \(x\) 序列之和，借此中间变量我们可以将不等式转化为：</p>
<script type="math/tex; mode=display">\begin{cases}
2 \cdot a_1 \leq s_2-s_0 \leq 2 \cdot a_1+1 \\\  
3 \cdot a_2 \leq s_3-s_0 \leq 3 \cdot a_2+2 \\\  
3 \cdot a_3 \leq s_4-s_1 \leq 3 \cdot a_3+2 \\\  
\cdots \cdots \\\  
3 \cdot a_{n-1} \leq s_n-s_{n-3} \leq 3 \cdot a_n+2 \\\  
2 \cdot a_n \leq s_n-s_{n-2} \leq 2 \cdot a_n+1 \\\
s_1-s_0 \geq 1 \\\
s_2-s_1 \geq 1 \\\
\cdots \cdots \\\  
s_n-s_{n-1} \geq 1
\end{cases}</script><p>这里的SPFA与原始的SPFA有所区别，在SPFA之前将所有节点加入队列，并且置dist为0，因为差分约束系统不保证图的连通性，所以需要事先建立一个虚拟节点作为源点，向所有边连接一条权值为0的有向边，以上的操作便是人工省略了虚拟源点的步骤。</p>
<h1 id="SPFA实现代码"><a href="#SPFA实现代码" class="headerlink" title="SPFA实现代码"></a>SPFA实现代码</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;queue&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> rep(i, x, n) for(int i = x; i &lt; n; i++)</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="type">const</span> <span class="type">int</span> MAXN = <span class="number">300</span> + <span class="number">6</span>;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> MAXM = <span class="number">2000</span> + <span class="number">6</span>;</span><br><span class="line"><span class="type">int</span> n, cur = <span class="number">0</span>;</span><br><span class="line"><span class="type">int</span> a[MAXN];</span><br><span class="line"><span class="type">int</span> head[MAXN];</span><br><span class="line"><span class="type">int</span> vis[MAXN], vis[MAXN], inq[MAXN], dist[MAXN];</span><br><span class="line"></span><br><span class="line"><span class="comment">//采用链式前向星的结构</span></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">Edge</span> &#123;</span><br><span class="line">	<span class="type">int</span> to;</span><br><span class="line">	<span class="type">int</span> next;</span><br><span class="line">	<span class="type">int</span> w;</span><br><span class="line">&#125;edge[MAXM];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addEdge</span><span class="params">(<span class="type">int</span> x, <span class="type">int</span> y, <span class="type">int</span> w)</span> </span>&#123;</span><br><span class="line">	edge[cur].to = y;</span><br><span class="line">	edge[cur].next = head[x];</span><br><span class="line">	edge[cur].w = w;</span><br><span class="line">	head[x] = cur++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">SPFA</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	queue&lt;<span class="type">int</span>&gt; qq;</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">0</span>, n + <span class="number">1</span>) &#123;</span><br><span class="line">		qq.<span class="built_in">push</span>(i);</span><br><span class="line">		vis[i] = <span class="number">1</span>;</span><br><span class="line">		dist[i] = <span class="number">0</span>;</span><br><span class="line">		inq[i] = <span class="number">1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">while</span> (!qq.<span class="built_in">empty</span>()) &#123;</span><br><span class="line">		<span class="type">int</span> x = qq.<span class="built_in">front</span>();</span><br><span class="line">		qq.<span class="built_in">pop</span>();</span><br><span class="line">		inq[x]++;	<span class="comment">//x进队的次数，超过n遍证明有负环</span></span><br><span class="line">		vis[x] = <span class="number">0</span>;</span><br><span class="line">		<span class="keyword">if</span> (inq[x] &gt; n) &#123;</span><br><span class="line">			cout &lt;&lt; <span class="string">&quot;No answer&quot;</span> &lt;&lt; endl;</span><br><span class="line">			<span class="keyword">return</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span> (<span class="type">int</span> i = head[x]; i != <span class="number">-1</span>; i = edge[i].next) &#123;</span><br><span class="line">			<span class="type">int</span> nx = edge[i].to;</span><br><span class="line">			<span class="keyword">if</span> (dist[nx] &lt; dist[x] + edge[i].w) &#123;</span><br><span class="line">				dist[nx] = dist[x] + edge[i].w;</span><br><span class="line">				<span class="keyword">if</span> (!vis[nx]) &#123;		<span class="comment">//如果没有拜访过</span></span><br><span class="line">					vis[nx] = <span class="number">1</span>;</span><br><span class="line">					qq.<span class="built_in">push</span>(nx);</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	ios::<span class="built_in">sync_with_stdio</span>(<span class="literal">false</span>);</span><br><span class="line">	cin.<span class="built_in">tie</span>(<span class="number">0</span>);</span><br><span class="line">	cout.<span class="built_in">tie</span>(<span class="number">0</span>);</span><br><span class="line">	<span class="built_in">memset</span>(head, <span class="number">-1</span>, <span class="built_in">sizeof</span>(head));</span><br><span class="line">	cin &gt;&gt; n;</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">1</span>, n + <span class="number">1</span>)  cin &gt;&gt; a[i];</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">0</span>, n - <span class="number">2</span>) &#123;</span><br><span class="line">		<span class="built_in">addEdge</span>(i + <span class="number">3</span>, i, -(a[i + <span class="number">2</span>] * <span class="number">3</span> + <span class="number">2</span>)); </span><br><span class="line">		<span class="built_in">addEdge</span>(i, i + <span class="number">3</span>, a[i + <span class="number">2</span>] * <span class="number">3</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">addEdge</span>(<span class="number">2</span>, <span class="number">0</span>, -(a[<span class="number">1</span>] * <span class="number">2</span> + <span class="number">1</span>));		<span class="comment">//对开头两个单独处理</span></span><br><span class="line">	<span class="built_in">addEdge</span>(<span class="number">0</span>, <span class="number">2</span>, a[<span class="number">1</span>] * <span class="number">2</span>);</span><br><span class="line">	<span class="built_in">addEdge</span>(n, n - <span class="number">2</span>, -(a[n] * <span class="number">2</span> + <span class="number">1</span>)); <span class="comment">//对结尾两个单独处理</span></span><br><span class="line">	<span class="built_in">addEdge</span>(n - <span class="number">2</span>, n, a[n] * <span class="number">2</span>);</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">1</span>, n + <span class="number">1</span>) </span><br><span class="line">		<span class="built_in">addEdge</span>(i - <span class="number">1</span>, i, <span class="number">1</span>);	<span class="comment">//每个数都要大于等于1</span></span><br><span class="line">	<span class="built_in">SPFA</span>();</span><br><span class="line">	a[<span class="number">1</span>] = dist[<span class="number">1</span>];</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">2</span>, n + <span class="number">1</span>)  </span><br><span class="line">		a[i] = dist[i] - dist[i - <span class="number">1</span>];</span><br><span class="line">	cout &lt;&lt; a[<span class="number">1</span>];</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">2</span>, n + <span class="number">1</span>)  </span><br><span class="line">		cout &lt;&lt; <span class="string">&#x27; &#x27;</span> &lt;&lt; a[i];</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>关于main函数中<code>ios::sync_with_stdio(false)</code>的相关用法简介，可见 <a href="/2020/02/21/iosSyncWithStdio/" title="关于ios::sync_with_stdio(false)和cin.tie(nullptr)">关于ios::sync_with_stdio(false)和cin.tie(nullptr)</a> </p>
<h1 id="思路（搜索-剪枝）"><a href="#思路（搜索-剪枝）" class="headerlink" title="思路（搜索+剪枝）"></a>思路（搜索+剪枝）</h1><h2 id="剪枝1"><a href="#剪枝1" class="headerlink" title="剪枝1"></a>剪枝1</h2><p>vis[][][]数组记录在到达第s个位置时（此时b[s],b[s-1]均已知），根据关系推知b[s+1] = 3*a[s]-b[s]-b[s-1]+i（因为题目给的是整数除法，其中 \(i \in (0 \cdots 2)\)，这样，当到达当前状态时（状态 : (s,b[s-1],b[s])），如果发现已经访问过了，说明这种状态不可能满足条件，否则程序已经找到满意的结果，可以直接输出了，这样可以直接剪枝掉之后的所有步骤，效率大大增加。</p>
<h2 id="剪枝2"><a href="#剪枝2" class="headerlink" title="剪枝2"></a>剪枝2</h2><p>用flag标记 是否已经找到解，如果找到，之后的所有未完成的搜索，直接返回。</p>
<p>注意：第一个位置与最后的位置单独处理。</p>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;set&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;cmath&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;queue&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;algorithm&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> rep(i,j,k) for(int i=j;i&lt;k;++i)</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> mst(a,b) memset((a),(b),sizeof(a))</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> LL;</span><br><span class="line"><span class="keyword">typedef</span> vector&lt;<span class="type">int</span>, <span class="type">int</span>&gt; pii;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> MAXN = <span class="number">305</span>;</span><br><span class="line"><span class="type">int</span> n;</span><br><span class="line"><span class="type">int</span> a[MAXN];</span><br><span class="line"><span class="type">int</span> b[MAXN];</span><br><span class="line"><span class="type">bool</span> vis[MAXN][MAXN][MAXN];</span><br><span class="line"><span class="type">bool</span> flag;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">dfs</span><span class="params">(<span class="type">int</span> s, <span class="type">int</span> p1, <span class="type">int</span> p2)</span> </span>&#123;</span><br><span class="line">	<span class="keyword">if</span> (vis[s][p1][p2] || flag) <span class="keyword">return</span>;</span><br><span class="line">	vis[s][p1][p2] = <span class="literal">true</span>;</span><br><span class="line">	<span class="keyword">if</span> (s == n - <span class="number">1</span>) &#123;</span><br><span class="line">		<span class="built_in">rep</span>(i, <span class="number">0</span>, <span class="number">3</span>) &#123;<span class="comment">//单独处理最后一个</span></span><br><span class="line">			<span class="keyword">if</span> ((b[n] = (<span class="number">3</span> * a[s] - p1 - p2 + i)) &gt; <span class="number">0</span> &amp;&amp; (b[n - <span class="number">1</span>] + b[n]) / <span class="number">2</span> == a[n]) &#123;</span><br><span class="line">				flag = <span class="literal">true</span>;</span><br><span class="line">				<span class="built_in">rep</span>(i, <span class="number">1</span>, n + <span class="number">1</span>) &#123;</span><br><span class="line">					<span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, b[i]);</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">0</span>, <span class="number">3</span>) &#123;</span><br><span class="line">		b[s + <span class="number">1</span>] = <span class="number">3</span> * a[s] - p1 - p2 + i;<span class="comment">//递推下一个位置的b[s+1]</span></span><br><span class="line">		<span class="keyword">if</span> (b[s + <span class="number">1</span>] &gt; <span class="number">0</span>) &#123; <span class="comment">// 可能有解</span></span><br><span class="line">			<span class="built_in">dfs</span>(s + <span class="number">1</span>, b[s], b[s + <span class="number">1</span>]);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;n);</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">1</span>, n + <span class="number">1</span>) <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;a[i]);</span><br><span class="line">	<span class="built_in">rep</span>(i, <span class="number">1</span>, <span class="number">2</span> * a[<span class="number">1</span>] + <span class="number">1</span>) &#123;<span class="comment">//最大只能是 2*a[1]</span></span><br><span class="line">		b[<span class="number">1</span>] = i; b[<span class="number">2</span>] = a[<span class="number">1</span>] * <span class="number">2</span> - b[<span class="number">1</span>];</span><br><span class="line">		<span class="built_in">dfs</span>(<span class="number">2</span>, b[<span class="number">1</span>], b[<span class="number">2</span>]);</span><br><span class="line">		b[<span class="number">1</span>] = i; b[<span class="number">2</span>] = a[<span class="number">1</span>] * <span class="number">2</span> - b[<span class="number">1</span>] + <span class="number">1</span>;</span><br><span class="line">		<span class="built_in">dfs</span>(<span class="number">2</span>, b[<span class="number">1</span>], b[<span class="number">2</span>]);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://blog.shimmerjordan.eu.org/2020/02/16/CCF20180904/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CCF/" rel="tag">CCF</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SPFA/" rel="tag">SPFA</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%B7%AE%E5%88%86%E7%BA%A6%E6%9D%9F/" rel="tag">差分约束</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%90%9C%E7%B4%A2%E5%89%AA%E6%9E%9D/" rel="tag">搜索剪枝</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/" rel="tag">算法练习</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/02/16/DifferentialConstraintAndShortestCircuit/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            差分约束与最短路
          
        </div>
      </a>
    
    
      <a href="/2020/02/13/starChain/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">前向星与链式前向星</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "StYfTMDp78X0EltFR16ve2q5-gzGzoHsz",
    app_key: "G4RPxRpXG6RwdfpnJefOSnyy",
    path: window.location.pathname,
    avatar: "wavatar",
    placeholder: "ヾﾉ≧∀≦)o来啊，快活啊!",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
   
<!-- minivaline评论 -->
<div id="mvcomments-box">
  <div id="mvcomments"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/minivaline@latest"></script>
<script>
    new MiniValine(Object.assign({"enable":true,"mode":"DesertsP","placeholder":"Write a Comment","math":true,"md":true,"enableQQ":true,"NoRecordIP":false,"visitor":true,"maxNest":6,"pageSize":6,"adminEmailMd5":"de8a7aa53d07e6b6bceb45c64027763d","tagMeta":["管理员","小伙伴","访客"],"master":["de8a7aa53d07e6b6bceb45c64027763d"],"friends":["b5bd5d836c7a0091aa8473e79ed4c25e","adb7d1cd192658a55c0ad22a3309cecf","3ce1e6c77b4910f1871106cb30dc62b0","cfce8dc43725cc14ffcd9fb4892d5bfc"],"lang":null,"emoticonUrl":["https://cdn.jsdelivr.net/npm/alus@latest","https://cdn.jsdelivr.net/gh/MiniValine/qq@latest","https://cdn.jsdelivr.net/gh/MiniValine/Bilibilis@latest","https://cdn.jsdelivr.net/gh/MiniValine/tieba@latest","https://cdn.jsdelivr.net/gh/MiniValine/twemoji@latest","https://cdn.jsdelivr.net/gh/MiniValine/weibo@latest"]}, {
	  el: '#mvcomments',
    }));
  const infoEle = document.querySelector('#mvcomments .info');
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
      infoEle.childNodes.forEach(function (item) {
          item.parentNode.removeChild(item);
      });
  }
</script>
<style>
	#mvcomments-box {
		padding: 5px 30px;
	}
	@media screen and (max-width: 800px) {
		#mvcomments-box {
		  padding: 5px 0px;
		}
	}
	.darkmode .MiniValine *{
		color: #f1f1f1!important;
	}
	.darkmode .commentTrigger{
		background-color: #403e3e !important;
	  }
	.darkmode .MiniValine .vpage .more{
		background: #21232F
	}
	.darkmode img{
		filter: brightness(30%)
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment.expand:before{
		background: linear-gradient(180deg, rgba(246,246,246,0), rgba(0,0,0,0.9))
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment.expand:after{
		background: rgba(0,0,0,0.9)
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment pre{
		background: #282c34
		border: 1px solid #282c34
	}
	.darkmode .MiniValine .vinputs-area .textarea-wrapper textarea{
		color: #000;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper input{
		color: #000;
	}
	.darkmode .MiniValine .vinputs-area .vextra-area .vsmile-icons{
		background: transparent;
	}
	.darkmode .MiniValine .vinputs-wrap{
		border-color: #b2b2b5;
	}
	.darkmode .MiniValine .vinputs-wrap:hover{
		border: 1px dashed #2196f3;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper{
		border-bottom: 1px dashed #b2b2b5;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper:hover{
		border-bottom: 1px dashed #2196f3;
	}
	.darkmode .MiniValine .vbtn{
		background-color: transparent!important;
	}
	.darkmode .MiniValine .vbtn:hover{
		border: 1px dashed #2196f3;
	}
</style>

    
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2024
        <i class="ri-heart-fill heart_icon"></i> 鞠桥丹-QIAODAN JU
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s4.cnzz.com/z_stat.php?id=1279035150&amp;web_id=1279035150'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="丛烨-shimmerjordan"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">Home</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">Catalogue</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">Tags</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E9%9A%8F%E7%AC%94/">Essay</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">Archives</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">Friends</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/01/18/about">About</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯蓝莓汁吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->


<script src="/js/clickLove.js"></script>


<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>